package org.example.news_check.Controller;


import jakarta.annotation.Resource;
import org.example.news_check.Pojo.Comment;
import org.example.news_check.Pojo.Result;
import org.example.news_check.Service.CommentService;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    CommentService commentService;


    // 查询对应新闻的评论
    @GetMapping("/search/{newsId}")
    public Result getData(@PathVariable Integer newsId){
        return Result.success(commentService.findAll(newsId));
    }

    //新增评论
    @PostMapping("/addcomment")
    public Result commentRegister(@RequestBody Comment comment){

        return Result.success(commentService.add(comment));

    }

   //删除评论
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        commentService.delete(id);
        return Result.success();
    }

   //查看所有评论
    @PostMapping("/all")
    public Result page(@RequestBody Comment comment) {
        Integer newsId = comment.getNewsId();
        return Result.success(commentService.findByNewsId(newsId));
    }





}
